import moment from 'moment'
import { WindUtil } from '@/utils/util'
// 页面默认数据
const defaultPageData = {
	cnCalendarDetail: '',
	updateSite: '',
	cTime: '2023-03-30 10:00:00',
	temperature: '-',
	windDirect: 0,
	windSpeed: 1.6,
	conspicurity: 500,
	humidity: 10,
	rain: 0,
	hourRain: 0,
	alarmSignals: [
		// {
		// 	iconUrl: '/data/icon/weather/alarmSignal/台风黄色预警信号.png',
		// 	sigalType: '台风',
		// 	signalLevel: '黄色',
		// 	statusId: 0
		// },
		// {
		// 	iconUrl: '/data/icon/weather/alarmSignal/道路结冰橙色预警信号.png',
		// 	sigalType: '道路结冰',
		// 	signalLevel: '橙色',
		// 	statusId: 0
		// },
		// {
		// 	iconUrl: '/data/icon/weather/alarmSignal/雪灾红色预警信号.png',
		// 	sigalType: '雪灾',
		// 	signalLevel: '红色',
		// 	statusId: 0
		// }
	],
	exponentForecasts: [
		{
			iconUrl: '/data/icon/weather/exponentForecast/沙发.png',
			title: '舒适度指数',
			desc: '较舒适'
		},
		{
			iconUrl: '/data/icon/weather/exponentForecast/健身.png',
			title: '晨练指数',
			desc: '不宜锻炼'
		},
		{
			iconUrl: '/data/icon/weather/exponentForecast/太阳.png',
			title: '中暑指数',
			desc: ' 不会中暑'
		},
		{
			iconUrl: '/data/icon/weather/exponentForecast/紫外线强.png',
			title: '紫外线指数',
			desc: '强度弱'
		},
		{
			iconUrl: '/data/icon/weather/exponentForecast/穿衣.png',
			title: '穿衣指数',
			desc: '穿套装、夹克类'
		},
		{
			iconUrl: '/data/icon/weather/exponentForecast/病毒.png',
			title: '感冒指数',
			desc: '感冒易发'
		}
	]
}

// 过滤 数字 图表数值只能为数字
const filterNumber = (arr) => {
	const newArr = []
	arr.map((t) => {
		if (isNaN(t)) {
			newArr.push(null)
		} else {
			newArr.push(parseFloat(t))
		}
	})
	return newArr
}

const changeTime = (data) => {
	const val = data.toString()
	const year = val.slice(0, 4)
	const month = val.slice(4, 6)
	const days = val.slice(6, 8)
	// const hour = val.slice(8, 10)
	// const min = val.slice(10, 12)
	// const sec = val.slice(12, 14)
	// ${hour}:${min}:${sec}
	const res = `${year}-${month}-${days}`
	return res
}

const dealTenData = (list) => {
	let today = moment().format('YYYY-MM-DD')
	let dayTem = []
	let nightTem = []
	let xdata = []
	list.map((el, index) => {
		el.W_DATE = changeTime(el.W_DATE)
		el.date = moment(el.W_DATE).format('MM/DD')
		if (el.W_DATE == today) {
			el.WEEK = '今日'
		}
		el.dayPath = `/data/icon/weather/day/${el.WEATHER_CODE_DAYTIME}.png`
		el.nightPath = `/data/icon/weather/night/${el.WEATHER_CODE_NIGHT}.png`
		dayTem.push(el.TEMPERATURE_HIGH)
		nightTem.push(el.TEMPERATURE_LOW)
		xdata.push(index)
		return el
	})

	let option = {
		grid: {
			top: '20%',
			left: '0%',
			right: '0%',
			bottom: '30%'
			// containLabel: true
		},
		legend: {
			show: false
		},
		xAxis: {
			type: 'category',
			data: xdata,
			axisLabel: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLine: {
				show: false,
				//坐标轴轴线相关设置
				lineStyle: {
					color: '#E5E9ED'
					// opacity:0.2
				}
			},
			splitLine: {
				//坐标轴在 grid 区域中的分隔线。
				show: false,
				lineStyle: {
					color: '#E5E9ED'
					// 	opacity:0.1
				}
			}
		},
		yAxis: [
			{
				type: 'value',
				// splitNumber: 80,
				min: function (value) {
					return value.min
				},
				max: function (value) {
					return value.max + 5
				},
				// minInterval: 0.15,
				// min: (val) => {
				// 	return val.min - 45
				// },
				// max: (val) => {
				// 	return val.max + 10
				// },
				axisLabel: {
					show: false
				},
				axisLine: {
					show: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false,
					lineStyle: {
						show: false
						// type: 'dashed',
					}
				}
			}
		],
		title: {
			show: false
		},
		tooltip: {
			trigger: 'axis',
			show: false
		},
		series: [
			// {
			// 	name: '最高温',
			// 	type: 'line',
			// 	smooth: 0.25, //是否平滑
			// 	showAllSymbol: true,
			// 	// symbol: 'image://./static/images/guang-circle.png',
			// 	symbol: 'circle',
			// 	symbolSize: 5,
			// 	lineStyle: {
			// 		normal: {
			// 			width: 2, //设置线条粗细
			// 			color: 'rgba(249, 182, 50, 1)',
			// 			type: 'dotted'
			// 		}
			// 	},
			// 	label: {
			// 		show: true,
			// 		position: 'top',
			// 		formatter: '{c} ℃'
			// 	},
			// 	itemStyle: {
			// 		color: 'rgba(249, 182, 50, 1)'
			// 	},
			// 	tooltip: {
			// 		show: true
			// 	},
			// 	data: [24, 25, 26, '-', '-', '-', '-']
			// },
			{
				name: '最高温',
				type: 'line',
				smooth: true, //是否平滑
				showAllSymbol: true,
				// symbol: 'image://./static/images/guang-circle.png',
				symbol: 'circle',
				symbolSize: 5,
				lineStyle: {
					normal: {
						width: 2, //设置线条粗细
						color: '#FF8A00'
					}
				},
				label: {
					show: true,
					position: 'top',
					formatter: '{c} ℃'
				},
				itemStyle: {
					color: '#FF8A00'
				},
				tooltip: {
					show: true
				},
				data: dayTem
			},
			// {
			// 	name: '最低温',
			// 	type: 'line',
			// 	smooth: true, //是否平滑
			// 	showAllSymbol: true,
			// 	// symbol: 'image://./static/images/guang-circle.png',
			// 	symbol: 'circle',
			// 	symbolSize: 5,
			// 	lineStyle: {
			// 		normal: {
			// 			color: 'rgba(0, 173, 239, 1)',
			// 			width: 2,
			// 			type: 'dotted'
			// 		}
			// 	},
			// 	label: {
			// 		show: true,
			// 		position: 'bottom',
			// 		formatter: '{c} ℃'
			// 	},
			// 	itemStyle: {
			// 		color: 'rgba(0, 173, 239, 1)'
			// 	},
			// 	tooltip: {
			// 		show: true
			// 	},
			// 	data: [12, 10, 20, '-', '-', '-', '-']
			// },
			{
				name: '最低温',
				type: 'line',
				smooth: true, //是否平滑
				showAllSymbol: true,
				// symbol: 'image://./static/images/guang-circle.png',
				symbol: 'circle',
				symbolSize: 5,
				lineStyle: {
					normal: {
						color: '#00B2FF',
						width: 2
					}
				},
				label: {
					show: true,
					position: 'bottom',
					formatter: '{c} ℃'
				},
				itemStyle: {
					color: '#00B2FF'
				},
				tooltip: {
					show: true
				},
				data: nightTem
			}
		]
	}
	return { list, option }
}

const dealHourData = (obj) => {
	let arr = []
	obj.today.map((el) => {
		el.dayPath = `/data/icon/weather/day/${el.ico}.png`
		arr.push(el.temperature)
		el.date_time = changeTime(el.w_datetime)
		el.date_time = moment(el.date_time).format('DD')
		el.rotate = WindUtil.nameToDir(el.winddir)
		return el
	})
	let option = {
		id: 'option2',
		grid: {
			top: '30%',
			left: '0%',
			right: '0%',
			bottom: '20%'
			// containLabel: true
		},
		legend: {
			show: false
		},
		xAxis: {
			type: 'category',
			data: arr,
			axisLabel: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLine: {
				show: false,
				//坐标轴轴线相关设置
				lineStyle: {
					color: '#E5E9ED'
					// opacity:0.2
				}
			},
			splitLine: {
				//坐标轴在 grid 区域中的分隔线。
				show: false,
				lineStyle: {
					color: '#E5E9ED'
					// 	opacity:0.1
				}
			}
		},
		yAxis: [
			{
				min: function (value) {
					return value.min
				},
				max: function (value) {
					return value.max + 10
				},
				type: 'value',
				// splitNumber: 80,
				// minInterval: 0.15,
				// min: 0,
				axisLabel: {
					show: false
				},
				axisLine: {
					show: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false,
					lineStyle: {
						show: false,
						// type: 'dashed',
						opacity: 0.1
					}
				}
			}
		],
		title: {
			show: false
		},

		series: [
			{
				name: '温度',
				type: 'line',
				smooth: true, //是否平滑
				showAllSymbol: true,
				// symbol: 'image://./static/images/guang-circle.png',
				symbol: 'circle',
				symbolSize: 5,
				lineStyle: {
					normal: {
						color: 'rgba(0, 173, 239, 0.81)',
						width: 2
					}
				},
				label: {
					show: true,
					position: 'top',
					formatter: '{c} ℃'
				},
				itemStyle: {
					color: 'rgba(0, 173, 239, 1)'
				},

				data: arr
			}
		]
	}
	return { obj, option }
}
export { defaultPageData, dealTenData, dealHourData }
